﻿using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
using System.Runtime.InteropServices;
using System.Drawing.Printing;
using System.Threading;

namespace SpotifyHUD
{
    public partial class MainForm : Form
    {
        public MainForm()
        {
            InitializeComponent();
        }

        private void ButtonImageClose_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }

        private void ButtonImagePlay_Click(object sender, EventArgs e)
        {
            SpotiftyControler.Play();
        }

        private void ButtonImagePrevious_Click(object sender, EventArgs e)
        {
            SpotiftyControler.Prev();
        }

        private void ButtonImageNext_Click(object sender, EventArgs e)
        {
            SpotiftyControler.Next();
        }

        private void MainForm_Load(object sender, EventArgs e)
        {
            this.Height = 20;
            this.Width = 400;
            var wa = Screen.PrimaryScreen.WorkingArea;
            this.Location = new Point(wa.X - 200 + wa.Width / 2, wa.Y);
            (new Thread(this.UpdateTrack)).Start();
            DisableAltTab();
        }

        private void DisableAltTab()
        {

            // not in alt-tab
            int windowStyle = User32.GetWindowLong(Handle, User32.GWL_EXSTYLE);
            User32.SetWindowLong(Handle, User32.GWL_EXSTYLE, windowStyle | User32.WS_EX_TOOLWINDOW);
        }

        private void UpdateTrack()
        {
            Action updateLabel = () => this.Description.Text = SpotiftyControler.GetNowplaying();
            while (this.Visible)
            {
                this.Description.Invoke(updateLabel);
                Thread.Sleep(1000);
            }
        }

        private void ButtonImageExit_Click(object sender, EventArgs e)
        {
            Application.Exit();
        }
    }
}
